﻿using _2112A_2_MES._chubowen;
using _2112A_2_MES._sujiahao;
using _2112A_2_MES._XiangHe;
using _2112A_2_MES.ChuBoWen;
using _2112A_2_MES.ChuBoWens;
using Autofac.Core;
using FourGroups.Project;
using Microsoft.AspNetCore.Mvc;
using NuGet.Configuration;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace _2112A_2_MES.Web.Controllers
{
    public class ChuBoWenController : Controller
    {
        #region /// 服务实现
        /// <summary>
        /// 供应商管理
        /// </summary>
        private readonly MdVendorService _service;

        /// <summary>
        /// 物料产品管理
        /// </summary>
        private readonly MditemServiceChu _mditemServiceChu;

        /// <summary>
        /// 库存现有量
        /// </summary>
        private readonly ProductEntryFormService _productEntryFormRepository;

        /// <summary>
        /// 调拨转移表WmTransferService
        /// </summary>
        private readonly WmTransferService _wmTransferRepository;

        /// <summary>
        /// 生产退料表
        /// </summary>
        private readonly ProductionRejectionService _productionRejectionRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        /// <param name="mditemServiceChu"></param>
        public ChuBoWenController(MdVendorService service, MditemServiceChu mditemServiceChu, ProductEntryFormService productEntryFormRepository, WmTransferService wmTransferRepository, ProductionRejectionService productionRejectionRepository)
        {
            _service = service;//供应商管理
            _mditemServiceChu = mditemServiceChu;//物料产品管理
            _productEntryFormRepository = productEntryFormRepository;//库存现有量
            _productionRejectionRepository = productionRejectionRepository;//生产退料表
            _wmTransferRepository = wmTransferRepository;//调拨转移表
        }
        #endregion

        #region /// 首页
        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }
        #endregion

        #region /// Mditem 物料产品管理
        /// <summary>
        /// 物料产品管理（显示视图）
        /// </summary>
        /// <returns></returns>
        public IActionResult ProductManagementchu()
        {
            return View();
        }

        /// <summary>
        /// 新增物料产品（显示视图）
        /// </summary>
        /// <returns></returns>
        public IActionResult AddMditemView()
        {
            return View();
        }
        
        /// <summary>
        /// 编辑物料产品（显示视图）
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdMditemView()
        {
            return View();
        }

        /// <summary>
        /// 获取物料产品列表
        /// </summary>
        /// <param name="itemCode">物料产品编码</param>
        /// <param name="itemName">物料产品名称</param>
        /// <returns>返回物料产品泛型集合</returns>
        public async Task<InterSelect<object>> GetMditemList(string? itemCode, string? itemName, int pageIndex, int pageSize)
        {
            var result = await _mditemServiceChu.GetMditemList(itemCode, itemName, pageIndex, pageSize);
            return result;
        }

        /// <summary>
        /// 新增物料产品
        /// </summary>
        /// <param name="mditem"></param>
        /// <returns></returns>
        public async Task<int> AddMditem(MdItem mditem)
        {
            var result = await _mditemServiceChu.AddMditem(mditem);
            return result;
        }

        /// <summary>
        /// 删除物料产品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DeleteMditem(int id)
        {
            int i = await _mditemServiceChu.DeleteMditem(id);
            return i;
        }

        /// <summary>
        /// 获取物料产品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<MdItem> GetMditem(int id)
        {
            var result = await _mditemServiceChu.GetMditem(id);
            return result;
        }

        /// <summary>
        /// 修改物料产品
        /// </summary>
        /// <param name="mditem"></param>
        /// <returns></returns>
        public async Task<int> UpdateMditem(MditemDTO mditem)
        {
            int i = await _mditemServiceChu.UpdateMditem(mditem);
            return i;
        }
        #endregion

        #region /// MdVendor 供应商管理

        /// <summary>
        /// 供应商管理（显示视图）
        /// </summary>
        /// <returns></returns>
        public IActionResult MdVendorView()
        {
            return View();
        }

        /// <summary>
        /// 供应商管理（添加视图）
        /// </summary>
        /// <returns></returns>
        public IActionResult AddMdVendorView()
        {
            return View();
        }

        /// <summary>
        /// 供应商管理（修改视图）
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdMdVendorView()
        {
            return View();
        }

        /// <summary>
        /// 获取供应商信息
        /// </summary>
        /// <param name="vendorcode"></param>
        /// <param name="vendorname"></param>
        /// <param name="vendornick"></param>
        /// <param name="vendoren"></param>
        /// <returns>返回供应商信息的泛型集合</returns>
        public async Task<InterSelect<object>> GetMdVendorList(string? vendorcode, string? vendorname, string? vendornick, string? vendoren, int pageIndex, int pageSize)
        {
            var result = await _service.GetMdVendorList(vendorcode, vendorname, vendornick, vendoren, pageIndex, pageSize);
            return result;
        }

        /// <summary>
        /// 新增供应商
        /// </summary>
        /// <param name="mdVendor"></param>
        /// <returns></returns>
        public async Task<int> AddMdVendor(MdVendor mdVendor)
        {
            int i = await _service.AddMdVendor(mdVendor);
            return i;
        }

        /// <summary>
        /// 删除供应商
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DeleteMdVendor(int id)
        {
            int i= await _service.DeleteMdVendor(id);
            return i;
        }

        /// <summary>
        /// 获取客户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<MdVendor> GetMdVendorBuBy(int id)
        {
            var mdvendorList = await _service.GetMdVendorBuBy(id);
            return mdvendorList;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="mdVendor"></param>
        /// <returns></returns>
        ///[HttpGet]
        public async Task<int> UpdateMdVendor(MdVendorDTO mdVendor)
        {
            int i = await _service.UpdateMdVendor(mdVendor);
            return i;
        }
        #endregion

        #region /// ProductEntryForm 库存现有量
        /// <summary>
        /// 物料产品管理（显示视图）
        /// </summary>
        /// <returns></returns>
        public IActionResult ProductEntryFormView()
        {
            return View();
        }
        
        /// <summary>
        /// 新增库存现有量（显示视图）
        /// </summary>
        /// <returns></returns>
        public IActionResult AddProductEntryFormView()
        {
            return View();
        }
        
        /// <summary>
        /// 新增库存现有量（显示视图）
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdProductEntryFormView()
        {
            return View();
        }

        /// <summary>
        /// 获取库存现有量列表
        /// </summary>
        /// <param name="itemname"></param>
        /// <param name="warehousename"></param>
        /// <param name="expiredate"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<InterSelect<object>> GetProductEntryFormList(string? itemname, string? warehousename, string? expiredate, int pageIndex, int pageSize)
        {
            var productentryformList = await _productEntryFormRepository.GetProductEntryFormList(itemname, warehousename, expiredate, pageIndex, pageSize);
            return productentryformList;
        }

        /// <summary>
        /// 新增库存现有量
        /// </summary>
        /// <param name="productentryform"></param>
        /// <returns></returns>
        public async Task<int> AddProductEntryForm(ProductEntryForm productentryform)
        {
            var result = await _productEntryFormRepository.AddProductEntryForm(productentryform);
            return result;
        }

        /// <summary>
        /// 删除库存现有量
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DeleteProductEntryForm(int id)
        {
            int i =  await _productEntryFormRepository.DeleteProductEntryForm(id);
            return i;
        }

        /// <summary>
        /// 获取库存现有量
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<ProductEntryForm> GetProductEntryForm(int id)
        {
            var productentryform = await _productEntryFormRepository.GetProductEntryForm(id);
            return productentryform;
        }

        /// <summary>
        /// 修改库存现有量
        /// </summary>
        /// <param name="productentryform"></param>
        /// <returns></returns>
        public async Task<int> UpdateProductEntryForm(ProductEntryFormDTO productentryform)
        {
            var result = await _productEntryFormRepository.UpdateProductEntryForm(productentryform);
            return result;
        }
        #endregion

        #region /// ProductionRejection 生产退料表
        /// <summary>
        /// 显示生产退料表（显示视图）
        /// </summary>
        /// <returns></returns>
        public IActionResult ProductionRejectionView()
        {
            return View();
        }

        /// <summary>
        /// 修改生产退料表（显示视图）
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdProductionRejectionView()
        {
            return View();
        }

        /// <summary>
        /// 修改生产退料表（显示视图）
        /// </summary>
        /// <returns></returns>
        public IActionResult AddProductionRejectionView()
        {
            return View();
        }

        /// <summary>
        /// 获取生产退料表
        /// </summary>
        /// <param name="rtcode"></param>
        /// <param name="workordercode"></param>
        /// <param name="warehousename"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<InterSelect<object>> GetProductionRejectionList(string? rtcode, string? workordercode, string? warehousename, int pageIndex, int pageSize)
        {
            var productionrejectionList = await _productionRejectionRepository.GetProductionRejectionList(rtcode, workordercode, warehousename, pageIndex, pageSize);
            return productionrejectionList;
        }

        /// <summary>
        /// 新增生产退料表
        /// </summary>
        /// <param name="productionRejection"></param>
        /// <returns></returns>
        public async Task<int> AddProductionRejection(ProductionRejection productionRejection)
        {
            var result = await _productionRejectionRepository.AddProductionRejection(productionRejection);
            return result;
        }

        /// <summary>
        /// 删除生产退料表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DeleteProductionRejection(int id)
        {
            var result = await _productionRejectionRepository.DeleteProductionRejection(id);
            return result;
        }

        /// <summary>
        /// 获取物料产品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<ProductionRejection> GetProductionRejection(int id)
        {
            var result = await _productionRejectionRepository.GetProductionRejection(id);
            return result;
        }

        /// <summary>
        /// 修改物料产品
        /// </summary>
        /// <param name="productionRejectionDTO"></param>
        /// <returns></returns>
        public async Task<int> UpdateProductionRejection(ProductionRejectionDTO productionRejectionDTO)
        {
            var result = await _productionRejectionRepository.UpdateProductionRejection(productionRejectionDTO);
            return result;
        }
        #endregion

        #region /// WmTransfer 调拨转移表
        /// <summary>
        /// 获取调拨转移表
        /// </summary>
        /// <param name="transfername"></param>
        /// <param name="fromwarehousename"></param>
        /// <param name="towarehousename"></param>
        /// <param name="clientId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<InterSelect<object>> GetWmTransferList(string? transfername, string? fromwarehousename, string? towarehousename, string? clientId, int pageIndex, int pageSize)
        {
            var wmTransferList = await _wmTransferRepository.GetWmTransferList(transfername, fromwarehousename, towarehousename, clientId, pageIndex, pageSize);
            return wmTransferList;
        }

        /// <summary>
        /// 新增调拨转移
        /// </summary>
        /// <param name="wmTransfer"></param>
        /// <returns></returns>
        public async Task<int> AddWmTransfer(WmTransfer wmTransfer)
        {
            int i = await _wmTransferRepository.AddWmTransfer(wmTransfer);
            return i;
        }

        /// <summary>
        /// 删除调拨转移表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DeleteWmTransfer(int id)
        {
            int i = await _wmTransferRepository.DeleteWmTransfer(id);
            return i;
        }

        /// <summary>
        /// 获取调拨转移
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<WmTransfer> GetWmTransfer(int id)
        {
            var result = await _wmTransferRepository.GetWmTransfer(id);
            return result;
        }

        /// <summary>
        /// 修改调拨转移
        /// </summary>
        /// <param name="wmTransferDTO"></param>
        /// <returns></returns>
        public async Task<int> UpdateWmTransfer(WmTransferDTO wmTransferDTO)
        {
            int i = await _wmTransferRepository.UpdateWmTransfer(wmTransferDTO);
            return i;
        }
        #endregion
    }
}
